package com.baixiaowen.server;

import com.baixiaowen.com.disruptor.MessageConsumer;
import com.baixiaowen.com.entity.TranslatorData;
import com.baixiaowen.com.entity.TranslatorDataWapper;
import io.netty.channel.ChannelHandlerContext;

public class MessageConsumerImpl4Server extends MessageConsumer {

    public MessageConsumerImpl4Server(String consumerId) {
        super(consumerId);
    }

    @Override
    public void onEvent(TranslatorDataWapper event) throws Exception {
        // 1. 业务处理逻辑
        TranslatorData request = event.getData();
        ChannelHandlerContext ctx = event.getCtx();
        System.err.println("Server端: id=" + request.getId() + ", name=" + request.getName() + ", message=" + request.getMessage());

        // 2. 回送响应信息
        TranslatorData response = new TranslatorData();
        response.setId("resp: " + request.getId());
        response.setName("resp: " + request.getName());
        response.setMessage("resp: " + request.getMessage());
        // 写出response响应信息
        ctx.writeAndFlush(response);

    }
}
